
function count(mixed_var, mode) {
	var key, cnt = 0;
	if (mode == 'COUNT_RECURSIVE')
		mode = 1;
	if (mode != 1)
		mode = 0;
	for (key in mixed_var) {
		cnt++;
		if (mode == 1
				&& mixed_var[key]
				&& (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object)) {
			cnt += count(mixed_var[key], 1);
		}
	}
	return cnt;
}


$.fn.deserialize = function(d,config) {
	var data= d;
	me  = this;

	if (d === undefined) {
		return me;
	}

	config = $.extend({ isPHPnaming	: false,
						overwrite	: true},config);
	
	if (d.constructor == Array)	{
		data={};
		for(var i=0; i<d.length; i++) {
			if (typeof data[d[i].name] != 'undefined') {
				if (data[d[i].name].constructor!= Array) {
					data[d[i].name]=[data[d[i].name],d[i].value];
				} else {
					data[d[i].name].push(d[i].value);
				}
			} else {
				data[d[i].name]=d[i].value;
			}
		}
	}

	// now data is a hash. insert each parameter into the form
	$('input,select,textarea',me)
	.each(function() {
			  var p=this.name;
			  var v = [];
			  
			  // handle wierd PHP names if required
			  if (config.isPHPnaming) {
				  p=p.replace(/\[\]$/,'');
			  }
			  if(p && data[p] != undefined) {
				  v = data[p].constructor == Array ? data[p] : [data[p]];
			  }
			  // Additional parameter overwrite
			  if (config.overwrite === true || data[p]) {
				  switch(this.type || this.tagName.toLowerCase()) {
				  case "radio":
				  case "checkbox":
					  this.checked=false;
					  for(var i=0;i<v.length;i++) {
						  this.checked|=(this.value!='' && v[i]==this.value);
					  }
					  break;
				  case "select-multiple" || "select":
					  for( i=0;i<this.options.length;i++) {
						  this.options[i].selected=false;
						  for(var j=0;j<v.length;j++) {
							  this.options[i].selected|=(this.options[i].value!='' && this.options[i].value==v[j]);
						  }
					  }
					  break;
				  case "button":
				  case "submit":
					  this.value=v.length>0?v.join(','):this.value;
						  break;
				  default:
					  this.value=v.join(',');
				  }
				  $(this).trigger('change');
			  }
		  });
	return me;
};


function checkLogin(){
	 $.post('/admin/index/isloged/',function(data){
     		if(data.logged==false){
     			
     		}
     });
}


$(document).ready(function() {
	

	$('.required').prepend('<span class="r">*</span>');
	
	$('.zend_text , .zend_text_area').live('focus',function(){$(this).addClass('ui-state-hover');})
	.live('blur',function(){$(this).removeClass('ui-state-hover');});
	
	
	$('.button').live('mouseover',function(){$(this).addClass('ui-state-hover');});
	$('.button').live('mouseout',function(){$(this).removeClass('ui-state-hover');});
	$("#admin_menu ul:first").treeview({
		animated: "medium",
		collapsed: true		
	});
	
	$("#custom_menu ul:first").treeview({
		persist: "location",
		animated: "medium",
		collapsed: true		
	});
	
	$("#admin_menu li.active > a:first").each(function(){
		$(this).addClass('act');
		
	});
	
	$("#admin_menu a:[href='#']").click(function(){$(this).closest('li').find('div.hitarea:first').trigger('click');return false;});
	if($(".floatfixed").size()>0){
	var offset = $(".floatfixed").offset();
	var topPadding = 55;
	$(window).scroll(function() {
		if ($(window).scrollTop() > offset.top) {
			$(".floatfixed").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding});
		}
		else {$(".floatfixed").stop().animate({marginTop: 0});};
	});
	}
	
	
	
	

	//window.setInterval("checkLogin();", 2000);



	
	
});

